var gulp = require('gulp'),
    del = require('del'),
    pug = require('gulp-pug'),
    stylus = require('gulp-stylus');

const production = process.env.NODE_ENV === 'production';
const cfg = {
    DIST: 'dist',
    COPY_RES: 'static/**/*.*',
}

gulp.task('copy', () => {
    gulp.src(cfg.COPY_RES, { base: '.' })
        .pipe(gulp.dest(cfg.DIST))
})

gulp.task('template', () => {
    gulp.src(['src/index.pug', 'src/pages/*/*.pug'], { base: './src' })
        .pipe(pug(
            {
                pretty: !production,
                data: {
                    s: 'static'
                }
            }
        ))
        .pipe(gulp.dest(cfg.DIST))
})

gulp.task('style', () => {
    gulp.src(['src/index.stylus', 'src/pages/*/*.stylus'], { base: './src' })
        .pipe(stylus({
            'include css': true,
            compress: production
        }))
        .pipe(gulp.dest(cfg.DIST))
})

gulp.task('clean', () => {
    del.sync(cfg.DIST)
})
gulp.task('default', ['clean'], () => {
    gulp.start(['copy', 'template', 'style'])
})